package draw_0724;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.EventListener;

public class draw implements MouseListener, ActionListener {
    public Graphics gr;
    public int x1,y1,x2,y2,x3,y3;
    public String name;
    public int flag =1;

    public void actionPerformed(ActionEvent e){
        name=e.getActionCommand();
        System.out.println("点击按钮 "+name);


    }


        public void mouseClicked(MouseEvent e){
            x3=e.getX();
            y3=e.getY();
            if("三角形".equals(name)){
                gr.drawLine(x1,y1,x3,y3);
                gr.drawLine(x3,y3,x2,y2);
                flag=1;
                System.out.println("x3="+x3+"     y3="+y3);

            }

        }
        public void mousePressed(MouseEvent e){
        if(flag==1) {
            x1 = e.getX();
            y1 = e.getY();
        }

        }
        public void mouseReleased(MouseEvent e){
        if(flag==1) {
            x2 = e.getX();
            y2 = e.getY();
        }
        if("三角形".equals(name)){
            gr.drawLine(x1,y1,x2,y2);
            flag++;
        }


        }
        public void mouseEntered(MouseEvent e){

        }
        public void mouseExited(MouseEvent e) {

        }



}
